

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class Zip {

	Connection conn;
	
	public Zip() {
		
		String url = "jdbc:oracle:thin:@127.0.0.1:1521";
		String user = "hr";
		String passwd = "hr";
		try {
			// 1) ����Ŭ ����̹� �Τ���
			Class.forName("oracle.jdbc.driver.OracleDriver");


			conn = DriverManager.getConnection(url, user, passwd);

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public Vector<ZipCode> getZip(String dong) {
		Vector v = new Vector<ZipCode>();
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		try {
			String sql = "select * from zipcode where dong like ?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "%" + dong + "%");
			rs = pstmt.executeQuery();
			
			while (rs.next()) {
				ZipCode zc = new ZipCode();
				zc.setZipcode(rs.getString("zipcode"));
				zc.setSido(rs.getString("sido"));
				zc.setGugun(rs.getString("gugun"));
				zc.setDong(rs.getString("dong"));
				zc.setBunji(rs.getString("bunji"));
				if (rs.getString("bunji") == null) {
					zc.setBunji("");
				}
				zc.setRi(rs.getString("ri"));
				if (rs.getString("ri") == null) {
					zc.setRi("");
				}
				v.add(zc);			
			}
			
		} catch (SQLException ex) {
			ex.printStackTrace();
		} finally {
			try {
				rs.close();
				pstmt.close();
				conn.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			return v;
		}
		
	}

	
	public static void main(String[] args) {
		
		Zip z = new Zip();
		Vector<ZipCode> myZip = z.getZip("������");
		for (int i = 0; i < myZip.size(); i++) {
			System.out.println(myZip.get(i));
		}
	}
}
